﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;

namespace ProgrammersCalculator.View
{
    /// <summary>
    /// Interaction logic for CsvToXml.xaml
    /// </summary>
    public partial class CsvToXml : UserControl
    {
        public CsvToXml()
        {
            InitializeComponent();
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {

       
        }

        private void Convert_Click(object sender, RoutedEventArgs e)
        { // var lines = File.ReadAllLines(@"D:\test.csv");

            var lines = txtInput.Text.Split(new char[] { '\n' });
            var xml = new XElement("TopElement",
                                    lines.Select(line =>
                                        new XElement("Item", line.Split(',')
                                    .Select((column, index) =>
                                        new XElement("Column" + index, column)))));
            xml.Save(@"D:\xmlout.xml");
            txtOutput.Text = xml.ToString();

        }
    }
}
